<script setup>
import BlogCard from "@/views/blog/BlogCard.vue"
import SearchBar from "@/components/SearchBar.vue"
import appStore from "@/stores"
import { onMounted, ref } from "vue"
import { GetBlogsAll } from "@/apis/allAPI/blog"

const blogs = ref(null)
const latestBlogs = ref([])

onMounted(() => {
  GetBlogsAll("topBlogs", (rData) => {
    blogs.value = rData
    // 获取最新的五篇博客
    latestBlogs.value = rData ? rData : []
    appStore.homeviewStore.isLoading = false
  })
})
</script>

<template>
  <div style="display: flex; flex-direction: column; gap: 10px">
    <SearchBar />
    <BlogCard v-for="blog in latestBlogs" :key="blog.id" :blog="blog" />
  </div>
</template>

<style scoped>
.square-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.latest-blogs {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.section-title i {
  color: var(--primary);
}

.blogs-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 响应式设计 */
@media (max-width: 900px) {
  .square-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .square-cards {
    gap: 15px;
  }

  .blogs-list {
    gap: 15px;
  }

  .section-title {
    font-size: 20px;
  }
}
</style>
